<?php
require_once("template/header.php");

function curl_get($url) {
	
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);  
  return $data;		
}

function writeError(){
	echo 'ERROR!';
}


function handle_time($string){
	return str_replace(array('T','Z')," ", $string);
}

function renameStuff($string){
	switch ($string){
		case 'tipconcurs':return 'Concurs';
		case 'titlu':return 'Titlu';
		case 'datapublicare':return 'Data publicării';
		case 'dataprobapractica':return 'Data proba practică';
		case 'dataprobascrisa':return 'Data probă scrisă';
		case 'dataprobainterviu':return 'Data probă interviu';
		case 'probait':return 'Probă IT';
		case 'probals':return 'Probă limbi străine';
		case 'conditiiparticipare':return 'Condiţii participare';
		case 'bibliografie':return 'Bibilografie';
		case 'locdesfasurare': return 'Loc desfăşurare';
		case 'statusconcurs':return 'Status concurs';
		case 'descrierestatusconcurs':return 'Descriere status concurs';
		case 'tipangajator':return 'Tip angajator';
		case 'angajator':return 'Angajator';
		case 'websiteangajator':return 'Website angajator';
		case 'telefonangajator':return 'Telefon angajator';
		case 'judet':return 'Judeţ';
		case 'localitate':return 'Localitate';
		case 'tip':return 'Job';
		case 'clasa':return 'Clasa';
		case 'tipcompartiment':return 'Tip compartiment';
		case 'denumirecompartiment':return 'Denumire compartiment';
		default:return 'EROR!+'.$string;
	}
}

$id = $_GET['entityid'];

	$url='http://rogovdata.cloudapp.net:8080/v1/RoGovOpenData/Posturi/?$filter='.rawurlencode('entityid eq guid\''.$id.'\'').'&format=json';
	
	$response=curl_get($url);
	$jsonSide=$response;
	
	$resurse=json_decode($response,TRUE);
	$resurse=$resurse['d'][0];
	$enddata[]=$resurse;
 	echo '<span id="jsonData" style="display:none;">'.json_encode($enddata).'</span>'; 
	//var_dump($response);
	$write=false;
	$rezultat=array();
	foreach ($resurse as $key => $value) {
		if ($key==="tipconcurs")
			$write=true;
		if ($write){
			if($value==="TRUE") $value = "Da";
			if($value==="FALSE") $value = "Nu";
			if (strstr($key,"dataproba") || strstr($key,"termenlimita") || strstr($key,"datapublicare"))
				$value=handle_time($value);
			if (!strstr($key,"latitudine") && !strstr($key,"longitudine"))
			
			$rezultat[$key]=$value;
		}
	}
	
	


 
 
?>
<script>
  $(document).ready(function(){
    initialize_map_small();
	populate_small_map2();
	centerall();
  });
</script>
<div class="row">
    	<div class="span5">
        	<h2><?php echo $rezultat['tip']; ?></h2>
          <div class="fb-like" data-send="true" data-width="300" data-show-faces="false"></div>
        </div>
        	<div class="span2">
       		 <div id="map_canvas_small" class="hidden-phone pull-right" style="width:100%;margin-left:1%; height:150px; background-color:#ddd;"></div>
             </div>
        
    </div>

    
<div id="postdiv"><table class="table table-striped">
<?php
foreach ($rezultat as $key => $value) { ?>
	<tr><th style='text-align:left;'><?php echo renameStuff($key);?>:</th><td><?php echo $value;?></td></tr>
<?php } 	?>			

</table>
</div>
<?php
require_once("template/footer.php");
?>